import Taro, {Component} from '@tarojs/taro'
import {View, ScrollView, Text, Button} from '@tarojs/components'
import {connect} from '@tarojs/redux'
import {getTopicList, getNextTopicList} from '../../actions/topic'

import Topic from './topic'

@connect((store)=>{
  return {...store.topicList, curData: store.menu.curData}
},(dispatch)=>{
  return {
    getTopicList(params){
      dispatch(getTopicList(params))
    },
    getNextTopicList (params) {
      dispatch(getNextTopicList(params))
    }
  }
})
class TopicList extends Component {
  componentWillMount() {
    let {page, limit, curData} = this.props
    this.props.getTopicList && this.props.getTopicList({
      page, limit, tab: curData.key
    })
  }
  ScrollToLower() {
    let {page, limit, curData} = this.props
    console.log('到底了', page + 1);
    this.props.getNextTopicList && this.props.getNextTopicList({
      page: ++page, limit, tab: curData.key
    })
  }
  render () {
    let {list} = this.props
    return (
      <ScrollView
        style='height:100vh;'
        scrollY
        onScrollToLower={this.ScrollToLower.bind(this)}
      >
        {
           list.map(item => <Topic item={item} key={item.id} />)
        }
      </ScrollView>
    )
  }
}

export default TopicList